package com.gouwudai.gobbs.vo;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import com.litt.core.exception.BusiException;

/**
 * 用来保存用户登陆信息的对象，保存到SESSION中
 * @author <a href="mailto:littcai@hotmail.com">空心大白菜</a>
 * @date 2006-09-08
 * @version 1.0 
 */

public class UserLoginVO  implements java.io.Serializable {


    // Fields    

     /**
	 * 
	 */
	private static final long serialVersionUID = 1674024963854645149L;
	
	 private String sessionId;	//登陆用户的会话ID
	 private Integer userStyle; //显示风格 0-BBS风格，1-讨论区风格	 
	 private Integer hiddenFlag; //是否隐身 0-不隐身，1-隐身	
	 private String loginIp;	//当前登陆时的IP
	 
	 //以下是数据库字段
	 private Integer userId = new Integer(0);
     private String loginId = "";
     private String password = "";
     private String userName = "";
     private String trueName;
     private String sex;
     private String email;
     private Boolean emailOpenFlag = new Boolean(false);
    
     private String personalSign;
     private String personalIntro;
     private Date lastLoginTime;
     private Integer loginTimes;
     private Long onlineTime;
     private String lastLoginIp;
//     private BigDecimal userMoney = new BigDecimal(0);	//这些参数应该每次从数据库读取
//     private BigDecimal userDeposit = new BigDecimal(0);
//     private BigDecimal userMark = new BigDecimal(0);
//     private BigDecimal userCredit = new BigDecimal(0);
     private Integer userTopicCount;
     private Integer userReCount;
     private Boolean isdelFlag;
     private Boolean upfileOpenFlag = new Boolean(false);
     private Integer upfileSize;
     private Integer upfileUsedSize;
     private String personalPic;
     private Boolean picOpenFlag = new Boolean(false);
     private Integer gradeId = new Integer(0);	//用户等级

     private Map<Integer,String> permission = new HashMap<Integer,String>();    //全局权限
     
     private Map<String,String> classPermission = new HashMap<String,String>();   //分类/版面特有权限
     
    /**
     * 增加全局权限
     * @param permissionCode    权限代码
     * @param permissionName    权限名称
     */ 
 	public void addPermission(Integer permissionCode,String permissionName)
	{
		permission.put(permissionCode, permissionName);
	}

    /**
     * 删除指定全局权限
     * @param permissionCode    权限代码
     */
	public void removePermission(Integer permissionCode)
	{
		permission.remove(permissionCode);
	}
	
    /**
     * 判断是否拥有指定全局权限,没有权限则抛出异常页面,跳转到异常页面
     * @param permissionCode    权限代码
     */
	public boolean hasPermission(Integer permissionCode) throws BusiException
	{
		if(permission.containsKey(permissionCode))
			return true;
		else
			throw new BusiException("您没有当前功能的权限");
	}  
	
	/**
	 * 判断是否拥有指定全局权限,没有权限则返回FALSE
	 * @param permissionCode 权限代码
	 * @return
	 */
	public boolean withPermission(Integer permissionCode)
	{
		if(permission.containsKey(permissionCode))
			return true;
		else
			return false;
	}	

    /*************************************************************************************/
    
    /**
     * 增加分类/版面特有权限,目前采用classId组合permissionCode的方式,这样只需一个Map存放
     * @param classId    分类/版面ID
     * @param permissionCode    权限代码
     * @param permissionName    权限名称
     */ 
    public void addClassPermission(Integer classId,Integer permissionCode,String permissionName)
    {
        StringBuffer key = new StringBuffer();
        key.append(classId);
        key.append("-");
        key.append(permissionCode);        
        
        classPermission.put(key.toString(), permissionName);
    }
    
    /**
     * 移除分类/版面特有权限
     * @param classId
     * @param permissionCode
     */
    public void removeClassPermission(Integer classId,Integer permissionCode)
    {
        StringBuffer key = new StringBuffer();
        key.append(classId);
        key.append("-");
        key.append(permissionCode);     
        
        classPermission.remove(key.toString());
    }
    
    /**
     * 判断是否拥有指定分类/版面特有权限,没有权限则抛出异常页面,跳转到异常页面 
     * @param classId
     * @param permissionCode
     * @return
     * @throws BusiException
     */
    public boolean hasClassPermission(Integer classId,Integer permissionCode) throws BusiException
    {
        StringBuffer key = new StringBuffer();
        key.append(classId);
        key.append("-");
        key.append(permissionCode);  
        
        if(classPermission.containsKey(key.toString()))
            return true;
        else
            throw new BusiException("您没有当前功能的权限");
    }  
    
    /**
     * 如果没有分类/版面特有权限返回FALSE
     * @param classId
     * @param permissionCode
     * @return
     */
    public boolean withClassPermission(Integer classId,Integer permissionCode)
    {
        StringBuffer key = new StringBuffer();
        key.append(classId);
        key.append("-");
        key.append(permissionCode); 
        if(classPermission.containsKey(key.toString()))
            return true;
        else
            return false;
    }   
    
	
    // Property accessors

    public Integer getUserId() {
        return this.userId;
    }
    
    public void setUserId(Integer userId) {
        this.userId = userId;
    }

    public String getLoginId() {
        return this.loginId;
    }
    
    public void setLoginId(String loginId) {
        this.loginId = loginId;
    }

    public String getUserName() {
        return this.userName;
    }
    
    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getTrueName() {
        return this.trueName;
    }
    
    public void setTrueName(String trueName) {
        this.trueName = trueName;
    }

    public String getSex() {
        return this.sex;
    }
    
    public void setSex(String sex) {
        this.sex = sex;
    }

    public String getEmail() {
        return this.email;
    }
    
    public void setEmail(String email) {
        this.email = email;
    }

    public Boolean getEmailOpenFlag() {
        return this.emailOpenFlag;
    }
    
    public void setEmailOpenFlag(Boolean emailOpenFlag) {
        this.emailOpenFlag = emailOpenFlag;
    }
    
    public String getPersonalSign() {
        return this.personalSign;
    }
    
    public void setPersonalSign(String personalSign) {
        this.personalSign = personalSign;
    }

    public String getPersonalIntro() {
        return this.personalIntro;
    }
    
    public void setPersonalIntro(String personalIntro) {
        this.personalIntro = personalIntro;
    }

    public Date getLastLoginTime() {
        return this.lastLoginTime;
    }
    
    public void setLastLoginTime(Date lastLoginTime) {
        this.lastLoginTime = lastLoginTime;
    }

    public Integer getLoginTimes() {
        return this.loginTimes;
    }
    
    public void setLoginTimes(Integer loginTimes) {
        this.loginTimes = loginTimes;
    }

    public Long getOnlineTime() {
        return this.onlineTime;
    }
    
    public void setOnlineTime(Long onlineTime) {
        this.onlineTime = onlineTime;
    }

    public String getLastLoginIp() {
        return this.lastLoginIp;
    }
    
    public void setLastLoginIp(String lastLoginIp) {
        this.lastLoginIp = lastLoginIp;
    }

    public Integer getUserTopicCount() {
        return this.userTopicCount;
    }
    
    public void setUserTopicCount(Integer userTopicCount) {
        this.userTopicCount = userTopicCount;
    }

    public Integer getUserReCount() {
        return this.userReCount;
    }
    
    public void setUserReCount(Integer userReCount) {
        this.userReCount = userReCount;
    }

    public Boolean getUpfileOpenFlag() {
        return this.upfileOpenFlag;
    }
    
    public void setUpfileOpenFlag(Boolean upfileOpenFlag) {
        this.upfileOpenFlag = upfileOpenFlag;
    }

    public Integer getUpfileSize() {
        return this.upfileSize;
    }
    
    public void setUpfileSize(Integer upfileSize) {
        this.upfileSize = upfileSize;
    }

    public Integer getUpfileUsedSize() {
        return this.upfileUsedSize;
    }
    
    public void setUpfileUsedSize(Integer upfileUsedSize) {
        this.upfileUsedSize = upfileUsedSize;
    }

    public String getPersonalPic() {
        return this.personalPic;
    }
    
    public void setPersonalPic(String personalPic) {
        this.personalPic = personalPic;
    }

    public Boolean getPicOpenFlag() {
        return this.picOpenFlag;
    }
    
    public void setPicOpenFlag(Boolean picOpenFlag) {
        this.picOpenFlag = picOpenFlag;
    }

	public Integer isHiddenFlag() {
		return hiddenFlag;
	}

	public void setHiddenFlag(Integer hiddenFlag) {
		this.hiddenFlag = hiddenFlag;
	}

	public String getSessionId() {
		return sessionId;
	}

	public void setSessionId(String sessionId) {
		this.sessionId = sessionId;
	}

	public void setUserStyle(Integer userStyle) {
		this.userStyle = userStyle;
	}

	public String getLoginIp() {
		return loginIp;
	}

	public void setLoginIp(String loginIp) {
		this.loginIp = loginIp;
	}

	public Integer getGradeId() {
		return gradeId;
	}

	public void setGradeId(Integer gradeId) {
		this.gradeId = gradeId;
	}

	public Boolean getIsdelFlag() {
		return isdelFlag;
	}

	public void setIsdelFlag(Boolean isdelFlag) {
		this.isdelFlag = isdelFlag;
	}

	public Integer getUserStyle() {
		return userStyle;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}


}